import { Component, js } from 'cc';
import { Logger } from '../../../../wing/assets/src';
import { ccclass } from '../decorators';

/**
 * - 作者: DoooReyn
 * - 日期: 2023.10.30
 * - 名称: LoggerComponent
 * - 描述: 日志组件
 */
@ccclass('LoggerComponent')
export class LoggerComponent extends Component {
    /** 组件名称 */
    get uname() {
        return (this.constructor as any)['__uname__'] ?? js.getClassName(this.constructor);
    }

    /** 组件日志 */
    get logger() {
        return Logger.getLogger(this.uname);
    }

    protected onDestroy(): void {
        Logger.removeLogger(this.uname);
    }
}

/** 日志服务 */
export class LoggerService {
    /** 组件名称 */
    get uname() {
        return (this.constructor as any)['__uname__'] ?? js.getClassName(this.constructor);
    }

    /** 组件日志 */
    get logger() {
        return Logger.getLogger(this.uname);
    }
}
